﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Store.Manager.ERP.Common.Models
{
    public class CommonResponse<T> :CommonResponse where T :new()
    {
        public T? Data { get; set; }
        public static CommonResponse<T> OK(string? msg=null)
        {
            var result = new CommonResponse<T>()
            {
                Success = true,
                Message = msg,
                StatusCode = 200,
            };
            return result;
        }
        public static CommonResponse<T> OK(T data,string? msg = null)
        {
            var result = new CommonResponse<T>()
            {
                Success = true,
                Message = msg,
                StatusCode = 200,
                Data = data
            };
            return result;
        }

        public static CommonResponse<T> Error(string msg)
        {
            var result = new CommonResponse<T>
            {
                Success = false,
                Message = msg,
                StatusCode = 500
            };
            return result;
        }
        public static CommonResponse<T> Error(T data, string msg)
        {
            var result = new CommonResponse<T>
            {
                Success = false,
                Message = msg,
                StatusCode = 500,
                Data = data
            };
            return result;
        }
    }

    public class CommonResponse {
        public bool Success { get; set; }
        public string Message { get; set; }
        public int StatusCode { get; set; }

        public static CommonResponse OK(string? msg = null)
        {
            var result = new CommonResponse()
            {
                Success = true,
                Message = msg,
                StatusCode = 200,
            };
            return result;
        }

        public static CommonResponse Error(string msg, int errorCode = 500)
        {
            var result = new CommonResponse()
            {
                Success = true,
                Message = msg,
                StatusCode = errorCode,
            };
            return result;
        }
    }

}
